﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            //Console.BackgroundColor = ConsoleColor.DarkGreen;

            string[] array = { "Add","Edit","Delete","List","Exit"};
            int i;
            int j = 10;

            int index = 0;

            for (i = 0; i < array.Length; i++)
            {
               /**********************/
            
                j = Menubutton(array, 0, j, ConsoleColor.DarkGray);

                for (i = 1; i < array.Length; i++)
                {
                    j = Menubutton(array, i, j, ConsoleColor.DarkGreen);
                }
                ConsoleKeyInfo key = Console.ReadKey();
                
                if (key.Key == ConsoleKey.DownArrow)
                {
                    Down(array, ref j, ref key);
                }
            
                if  (key.Key == ConsoleKey.Enter)
                {
                    
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(40, 18);
                    Console.WriteLine("Add");
                }

                if (key.Key == ConsoleKey.UpArrow)
                {
                    Up(array, ref j, ref key);
                }
                      
                     
                 } 
                /**********************/
        }

        private static void Up(string[] array, ref int j, ref ConsoleKeyInfo key)
        {
            if (key.Key == ConsoleKey.UpArrow)
            {
                j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                j = Menubutton(array, 4, j, ConsoleColor.DarkGray);
                Console.ReadKey();
                if (key.Key == ConsoleKey.UpArrow)
                {
                    j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 3, j, ConsoleColor.DarkGray);
                    j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);
                    Console.ReadKey();
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 2, j, ConsoleColor.DarkGray);
                        j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                        Console.ReadKey();
                        if (key.Key == ConsoleKey.UpArrow) ;

                        {
                            j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 1, j, ConsoleColor.DarkGray);
                            j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                            Console.ReadKey();
                            if (key.Key == ConsoleKey.UpArrow)
                            {
                                j = Menubutton(array, 0, 10, ConsoleColor.DarkGray);
                                j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                                j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                                j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                                j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                            }
                        }
                    }
                }
            }
        }

            






            //Console.SetCursorPosition (0, 30);
            
            /*
            int i;
            int j = 10;
            for (i = 0; i < array.Length; i++)
            {
                 Console.WriteLine();
                 Console.SetCursorPosition(28, j);
                 Console.WriteLine("         "+"{0}"+"       ", array[i]);
                 j++;
             }

            ConsoleKeyInfo key = Console.ReadKey();

            if (key.Key == ConsoleKey.Enter)
            
            {
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
                Console.SetCursorPosition(28, j);
                Console.WriteLine("Add");
            }
            else if (key.Key == ConsoleKey.UpArrow)
            {
                Console.WriteLine("Up key was pressed");
            }
            else if (key.Key == ConsoleKey.DownArrow)
            {
                j = j - 15;
                for (i = 0; i < 3; i++)
                {
                    Console.BackgroundColor = ConsoleColor.DarkGray;
                    Console.SetCursorPosition(28, j);
                    Console.WriteLine("         " + "{0}" + "       ", array[i]);
                    j++;
                }
            }*/
        

        private static void Down(string[] array, ref int j, ref ConsoleKeyInfo key)
        {
            if (key.Key == ConsoleKey.DownArrow)
            {


                j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                j = Menubutton(array, 1, j, ConsoleColor.DarkGray);
                j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                Console.ReadKey();
                if (key.Key == ConsoleKey.DownArrow)
                {

                    j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 2, j, ConsoleColor.DarkGray);
                    j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                    j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                    Console.ReadKey();
                    if (key.Key == ConsoleKey.DownArrow)
                    {


                        j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                        j = Menubutton(array, 3, j, ConsoleColor.DarkGray);
                        j = Menubutton(array, 4, j, ConsoleColor.DarkGreen);

                        Console.ReadKey();
                        if (key.Key == ConsoleKey.DownArrow)
                        {
                            j = Menubutton(array, 0, 10, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 1, j, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 2, j, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 3, j, ConsoleColor.DarkGreen);
                            j = Menubutton(array, 4, j, ConsoleColor.DarkGray);
                            
                        }
                    }

                }

            }

        }

                                private static int Menubutton(string[] array, int i, int j, ConsoleColor color)
                                {
                                            Console.BackgroundColor = color;

                                            int n = 20 / 2;
                                            string str = array[i];
                                            int l = str.Length;
                                            int Rn = str.Length / 2;
                                            int fst = 0;
                                            if (str.Length % 2 > 0)
                                                    {
                                                        fst = n - Rn - 1;
                                                    }
                                            else
                                                    {
                                                        fst = n - Rn;
                                                    }
                                            int fnsh = n - Rn;


                                            Console.SetCursorPosition(28, j);
                                            for (int k = 0; k < 20; k++)
                                                    {
                                                        Console.Write(" ");

                                                    }
                                            j++;
                                            Console.SetCursorPosition(28, j);
                                            for (int k = 0; k < fst; k++)
                                                    {

                                                        Console.Write(" ");
                                                    }

                                            Console.Write("{0}", array[i]);

                                            for (int k = 0; k < fnsh; k++)
                                                    {
                                                        Console.Write(" ");

                                                    }
                                            j++;
                                            Console.SetCursorPosition(28, j);
                                            for (int k = 0; k < 20; k++)
                                                    {
                                                        Console.Write(" ");

                                                    }

                                            j++;
                                            return j;
                                   }






           }
        }
      
   
 
